//
//  DZKeTangController.m
//  dzyc
//
//  Created by 吴斌 on 2024/6/11.
//

#import "DZKeTangController.h"
#import "DZKeTangTableCell.h"
#import "DZMainController.h"
#import "DZWebViewController.h"
@interface DZKeTangController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *dzTableView;
@property (nonatomic, strong) NSArray * dzKeTangs;
@property (nonatomic, strong) NSArray * dzKeTangPlists;
@end

@implementation DZKeTangController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.hidden = YES;
    self.dzTableView.delegate = self;
    self.dzTableView.dataSource = self;
    [self makeKeTang];
}
- (void)makeKeTang{
    NSArray *baiKes = @[@"baike_1",@"baike_2",@"baike_3",@"baike_4",@"baike_5",@"baike_6",@"baike_7",@"baike_8"];
    NSArray *bixians = @[@"bixian_1",@"bixian_2",@"bixian_3",];
    NSArray *zhishis = @[@"zhishi_1",@"zhishi_2",@"zhishi_3",@"zhishi_4",@"zhishi_5",@"zhishi_6",@"zhishi_7",@"zhishi_8",@"zhishi_9"];
    NSMutableArray *dzKeTangArr = [NSMutableArray arrayWithArray:baiKes];
    [dzKeTangArr addObjectsFromArray:bixians];
    [dzKeTangArr addObjectsFromArray:zhishis];
    self.dzKeTangs = dzKeTangArr.copy;
    
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"KeTang" ofType:@"plist"];
    self.dzKeTangPlists = [NSArray arrayWithContentsOfFile:plistPath].firstObject;
    [self.dzTableView reloadData];
}
- (IBAction)navBack:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)navSet:(UIButton *)sender {
    DZMainController * mainCtrl = [[DZMainController alloc] init];
    [self.navigationController pushViewController:mainCtrl animated:YES];
}
#pragma mark -- UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dzKeTangs.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DZRatio(224);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DZKeTangTableCell *keTangTableCell = [DZKeTangTableCell showKeTangTableCell:tableView];
    keTangTableCell.keTangKey = self.dzKeTangs[indexPath.row];
    keTangTableCell.keTangDic = self.dzKeTangPlists[indexPath.row];
    return keTangTableCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DZWebViewController * webViewCtrl = [[DZWebViewController alloc] init];
    webViewCtrl.webUrl = [NSString stringWithFormat:@"http://tianxingdizhen.3o5y1b.top/dizhen/static/%@.html",self.dzKeTangs[indexPath.row]];
    [self.navigationController pushViewController:webViewCtrl animated:YES];
}
@end
